package brad.zimmerman.dungeon.game;

import java.util.ArrayList;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.widget.ImageView;
import android.widget.TextView;

class messageHolder extends Activity{
	private final Context context;
	private ArrayList<String> _messageHolder;
	private ArrayList<String> _headingHolder;
	private ArrayList<Integer> _usedMessages;
	private Dialog dialog;
	private TextView text;
	private ImageView image;
	private boolean upDialog;
	private float scale;
	private int player_level;
	messageHolder(Context context, float scale, int player_level){
		this.context = context;
		this._messageHolder = new ArrayList<String>();
		this._headingHolder = new ArrayList<String>();
		this._usedMessages = new ArrayList<Integer>();
		upDialog = false;
		dialog = new Dialog(context);
		dialog.setCancelable(true);
		dialog.setCanceledOnTouchOutside(true);
		dialog.setContentView(R.layout.custom_dialog);
		text = (TextView) dialog.findViewById(R.id.text);
		image = (ImageView) dialog.findViewById(R.id.image);
		this.scale = scale;
		this.player_level = player_level;
	}
	public int getSize(){
		return _messageHolder.size();
	}
	public void addMessage(String heading, String message, int msgNum){
		if(!_usedMessages.contains(msgNum)){
			_headingHolder.add(heading);
			_messageHolder.add(message);
			_usedMessages.add(msgNum);
		}
	}
	public void showMessages(boolean showAllways){
		//text.setTextSize(((scale)*(float).60));
		if(player_level == 0 || showAllways){

			if(!dialog.isShowing() && upDialog){
				if(_headingHolder.size()!=0 && _messageHolder.size()!=0){
					_headingHolder.remove(0);
					_messageHolder.remove(0);
				}
				upDialog = false;
			}
			if(_headingHolder.size()>0 && _messageHolder.size()>0){
			//System.out.println(_headingHolder.size() + " : " + _messageHolder.size());
			runOnUiThread(new Runnable() {
			public void run() {
							synchronized(dialog){
								dialog.setTitle(_headingHolder.get(0));
			    				text.setText(_messageHolder.get(0) + '\n');
			    				image.setImageResource(R.drawable.race_human);
		    					dialog.show();
		    					upDialog = true;
							}
				  }
			});
			}
			
			
		}
	}
	public void showSingleMessage(String header1, String body1, int image1){
		final String header = header1;
		final String body = body1;
		final int imaging = image1;
		//text.setTextSize(((scale)*(float).60));
		runOnUiThread(new Runnable() {
			public void run() {
							synchronized(dialog){
								dialog.setTitle(header);
			    				text.setText(body);
			    				image.setImageResource(imaging);
		    					dialog.show();
		    					upDialog = true;
							}
				  }
			});
	}
	public void showSingleMessageCharInfo(String header1, String body1, ClassGraphicObject pic){
		final String header = header1;
		final String body = body1;
		
		final Bitmap bitmap;
		Bitmap temp;
		temp = pic.getGraphic();
        bitmap = Bitmap.createBitmap(temp, 0, 0,temp.getWidth(), temp.getHeight(), pic.returnMatrix(temp.getWidth(),temp.getHeight(),(int) (scale*3),false), true);
        //canvas.drawBitmap(bitmap, (2* constant)+constant/2, ((20+3)* constant), null);
		//text.setTextSize(((scale)*(float).60));
		runOnUiThread(new Runnable() {
			public void run() {
							synchronized(dialog){
								dialog.setTitle(header);
			    				text.setText(body);
			    				image.setImageBitmap(bitmap);
		    					dialog.show();
		    					upDialog = true;
							}
				  }
			});
	}
	public void showSingleMessageCharInfo(String header1, String body1){
		final String header = header1;
		final String body = body1;

        //canvas.drawBitmap(bitmap, (2* constant)+constant/2, ((20+3)* constant), null);
		//text.setTextSize(((scale)*(float).60));
		runOnUiThread(new Runnable() {
			public void run() {
							synchronized(dialog){
								dialog.setTitle(header);
			    				text.setText(body);
			    				image.setImageBitmap(null);
		    					dialog.show();
		    					upDialog = true;
							}
				  }
			});
	}
	public void showSingleMessage(String header1, String body1, final Bitmap bitmap){
		final String header = header1;
		final String body = body1;
		//text.setTextSize(((scale)*(float).60));
		runOnUiThread(new Runnable() {
			public void run() {
							synchronized(dialog){
								dialog.setTitle(header);
			    				text.setText(body);
			    				image.setImageBitmap(bitmap);
		    					dialog.show();
		    					upDialog = true;
							}
				  }
			});
	}
}